﻿using System;
using System.Collections;
using UnityEngine;

namespace SizeboxUI
{
	// Token: 0x020003A4 RID: 932
	public class MainView : MonoBehaviour
	{
		// Token: 0x170003AE RID: 942
		// (get) Token: 0x06001879 RID: 6265 RVA: 0x0009ABAC File Offset: 0x00098DAC
		// (set) Token: 0x0600187A RID: 6266 RVA: 0x0009ABB4 File Offset: 0x00098DB4
		public MainView.Mode mode { get; private set; }

		// Token: 0x170003AF RID: 943
		// (get) Token: 0x0600187C RID: 6268 RVA: 0x0009ABC6 File Offset: 0x00098DC6
		// (set) Token: 0x0600187B RID: 6267 RVA: 0x0009ABBD File Offset: 0x00098DBD
		public GameObject mainCanvas { get; private set; }

		// Token: 0x170003B0 RID: 944
		// (get) Token: 0x0600187D RID: 6269 RVA: 0x0009ABCE File Offset: 0x00098DCE
		// (set) Token: 0x0600187E RID: 6270 RVA: 0x0009ABD6 File Offset: 0x00098DD6
		public EditView editMode { get; private set; }

		// Token: 0x0600187F RID: 6271 RVA: 0x0009ABE0 File Offset: 0x00098DE0
		public void ShowFPS(bool show)
		{
			MainView.fpsDisplayEnabled = show;
			GlobalPreferences.FpsCount.value = show;
			if (!show)
			{
				this.fpsDisplay.enabled = false;
			}
			if (show && !this.controller.paused)
			{
				this.fpsDisplay.enabled = true;
			}
		}

		// Token: 0x06001880 RID: 6272 RVA: 0x0009AC34 File Offset: 0x00098E34
		private void Start()
		{
			MainView.fpsDisplayEnabled = GlobalPreferences.FpsCount.value;
			if (UnityEngine.Object.FindObjectOfType<SmartConsole>() == null)
			{
				UnityEngine.Object.Instantiate<SmartConsole>(Resources.Load<SmartConsole>("UI/Console"));
			}
			this.controller = base.GetComponent<GameController>();
			this.mainCamera = base.GetComponent<MainCameraController>();
			base.gameObject.AddComponent<InterfaceControl>();
			this.mainCanvas = UnityEngine.Object.Instantiate<GameObject>(Resources.Load("UI/MainCanvas") as GameObject);
			this.fpsDisplay = this.mainCanvas.AddComponent<FPSDisplay>();
			if (!MainView.fpsDisplayEnabled)
			{
				this.fpsDisplay.enabled = false;
			}
			this.mainCanvas.GetComponent<Canvas>().scaleFactor = GlobalPreferences.UIScale.value;
			this.editMode = UnityEngine.Object.Instantiate<GameObject>(Resources.Load("UI/EditMode") as GameObject).AddComponent<EditView>();
			this.editMode.transform.SetParent(this.mainCanvas.transform, false);
			this.editMode.gameObject.SetActive(false);
			this.pause = UnityEngine.Object.Instantiate<GameObject>(Resources.Load<GameObject>("UI/PauseMenu")).AddComponent<PauseController>();
			this.pause.transform.SetParent(this.mainCanvas.transform, false);
			this.pause.SetGameController(this.controller);
			this.pause.main = this;
			this.pause.gameObject.SetActive(false);
			base.gameObject.AddComponent<MainInput>();
			this.mode = MainView.Mode.Play;
			Cursor.lockState = CursorLockMode.Locked;
		}

		// Token: 0x06001881 RID: 6273 RVA: 0x0009ADB8 File Offset: 0x00098FB8
		private void Update()
		{
			if (this.mainCanvas.GetComponent<Canvas>().scaleFactor != GlobalPreferences.UIScale.value)
			{
				this.mainCanvas.GetComponent<Canvas>().scaleFactor = GlobalPreferences.UIScale.value;
			}
			Cursor.visible = (!this.controller.gameStarted || this.controller.paused || this.mode == MainView.Mode.Edit);
		}

		// Token: 0x06001882 RID: 6274 RVA: 0x0009AE30 File Offset: 0x00099030
		public void ChangeMode()
		{
			this.mainCamera.SwitchCameraMode();
			if (this.mode == MainView.Mode.Play)
			{
				this.mode = MainView.Mode.Edit;
				this.editMode.gameObject.SetActive(true);
			}
			else
			{
				this.mode = MainView.Mode.Play;
				this.editMode.gameObject.SetActive(false);
			}
		}

		// Token: 0x06001883 RID: 6275 RVA: 0x0009AE88 File Offset: 0x00099088
		public void OpenPauseMenu()
		{
			this.controller.SetPausedState(true);
			SoundManager.This.SetPaused(true);
			this.pause.gameObject.SetActive(true);
			this.fpsDisplay.enabled = false;
		}

		// Token: 0x06001884 RID: 6276 RVA: 0x0009AEBE File Offset: 0x000990BE
		public void ClosePauseMenu()
		{
			this.controller.SetPausedState(false);
			SoundManager.This.SetPaused(false);
			this.pause.gameObject.SetActive(false);
			this.fpsDisplay.enabled = MainView.fpsDisplayEnabled;
		}

		// Token: 0x06001885 RID: 6277 RVA: 0x0009AEF8 File Offset: 0x000990F8
		public void TakeScreenshot()
		{
			base.StartCoroutine(this.ScreenshotRoutine());
		}

		// Token: 0x06001886 RID: 6278 RVA: 0x0009AF08 File Offset: 0x00099108
		private IEnumerator ScreenshotRoutine()
		{
			this.SetGizmo(false);
			this.mainCanvas.SetActive(false);
			IOManager.Instance.SaveScreenshot();
			yield return null;
			this.mainCanvas.SetActive(true);
			this.SetGizmo(true);
			yield break;
		}

		// Token: 0x06001887 RID: 6279 RVA: 0x0009AF23 File Offset: 0x00099123
		public void Take360Screenshot()
		{
			IOManager.Instance.Save360Screenshot();
		}

		// Token: 0x06001888 RID: 6280 RVA: 0x0009AF30 File Offset: 0x00099130
		private void SetGizmo(bool value)
		{
			if (this.placement == null)
			{
				this.placement = base.GetComponent<EditPlacement>();
			}
			if (this.placement == null)
			{
				return;
			}
			value = (value && this.mode == MainView.Mode.Edit);
			this.placement.enabled = value;
		}

		// Token: 0x06001889 RID: 6281 RVA: 0x0009AF8C File Offset: 0x0009918C
		private void OnApplicationFocus(bool hasFocus)
		{
			if (GlobalPreferences.BackgroundPause.value && !hasFocus)
			{
				this.OpenPauseMenu();
			}
		}

		// Token: 0x04001A99 RID: 6809
		private GameController controller;

		// Token: 0x04001A9D RID: 6813
		private MainCameraController mainCamera;

		// Token: 0x04001A9E RID: 6814
		public PauseController pause;

		// Token: 0x04001A9F RID: 6815
		private FPSDisplay fpsDisplay;

		// Token: 0x04001AA0 RID: 6816
		public static bool fpsDisplayEnabled = true;

		// Token: 0x04001AA1 RID: 6817
		private EditPlacement placement;

		// Token: 0x020003A5 RID: 933
		public enum Mode
		{
			// Token: 0x04001AA3 RID: 6819
			Play,
			// Token: 0x04001AA4 RID: 6820
			Edit
		}
	}
}
